//
//  TTApplication.h
//  Triton
//
//  Created by Tom on 2019/1/8.
//  Copyright © 2019 Tencent. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MABaseApplication.h"

@class TTAudioEngine;
@class TTEventDispatcher;
@class MAJSInspectorAgent;
@class TTJSService;
@class TTRenderView;
@class TTMessageTransferCenter;
@class JSValue;
@class TTWKWebView, TTWKUserScriptService;
@class TTWKBindingEngine, TTJavaScript;
@class TTScreenRecorder;
@class NS_MINI_INTERFACE_StModuleInfo;

typedef NS_OPTIONS(NSUInteger, TTAppState) {
    TTAppStateNone                    = 0,// 0
    TTAppStateInit                    = 1 << 1,// 2  冷启动
    TTAppStateResume                  = 1 << 2,// 4  热启动
    TTAppStateEnterForeground         = 1 << 3,// 8  应用切前台（如手q）
    TTAppStateViewAppear              = 1 << 4,// 16  从其他页面进入当前游戏页面 （如进入广告页，详情页）
    TTAppStateViewDisappear           = 1 << 5,//32  离开当前游戏页面 （如来开广告页，详情页）
    TTAppStateEnterBackground         = 1 << 6,//64  应用切后台（如手q）
    TTAppStateStop                    = 1 << 7,//128  点击关闭切换到后台
    TTAppStateEnd                     = 1 << 8,//256  点击关闭KillAPP
};

typedef NS_ENUM(NSUInteger, TTLaunchState) {
    TTLaunchStateBeginColdLaunch      = 0,//开始冷启动
    TTLaunchStateEndColdLaunch        = 1,//结束冷启动（第一帧出现）
    TTLaunchStateBeginHotLaunch       = 2,//开始热启动
    TTLaunchStateEndHotLaunch         = 3,//结束热启动
    TTLaunchStateBeginDownLoadJSSDK   = 4,//开始下载基础库（包含已下载完成）
    TTLaunchStateEndDownLoadJSSDK     = 5,//结束下载基础库
    TTLaunchStateBeginLoadJSSDK       = 6,//开始加载基础库
    TTLaunchStateEndLoadJSSDK         = 7,//结束加载基础库
    TTLaunchStateBeginDownLoadPackage = 8,//开始下载游戏主包（包含已下载完成）
    TTLaunchStateEndDownLoadPackage   = 9,//结束下载游戏主包
    TTLaunchStateBeginLoadPackage     = 10,//开始加载游戏主包
    TTLaunchStateRealBeginLoadPackage = 11,//真正开始加载开始读游戏js
    TTLaunchStateEndLoadPackage       = 12,//结束加载游戏主包
    TTLaunchStateBeginDownLoadPlugin  = 13,//开始下载游戏插件
    TTLaunchStateEndDownLoadPlugin    = 14,//结束下载游戏插件
};

NS_ASSUME_NONNULL_BEGIN
OBJC_EXTERN NSString * const TritonSystemAudioInterruptionBegin;
OBJC_EXTERN NSString * const TritonSystemAudioInterruptionEnd;
OBJC_EXTERN NSString * const TTViewControllerDidAppear;
OBJC_EXTERN NSString * const TritonSystemError;
OBJC_EXTERN NSString * const TTViewAppearFromAdv;
OBJC_EXTERN NSString * const MiniGameBeaconAppKey;

@interface TTApplication : MABaseApplication {
}

/// 进入后台的时间
@property (nonatomic, strong) NSDate *onEnterBGTime;

//广告是否显示
@property (nonatomic, assign) BOOL isAdShowing;

//闪屏广告是否正在展示
@property (nonatomic, assign, readonly) BOOL isLaunchAdShowing;

//是否点击过关闭按钮
@property (nonatomic, assign) BOOL hadClosed;

//是否点击过关闭按钮
@property (nonatomic, assign) BOOL needConfigViewAfterViewDidLoad;

//真机调试
@property (nonatomic, strong, readonly) MAJSInspectorAgent *inspectorAgent;

//标记小游戏是否正在重启
@property (nonatomic, assign, readonly) BOOL isRestartApp;

@property (nonatomic, strong, readonly) TTWKWebView *gameWebView;
@property (nonatomic, strong, readonly) TTWKUserScriptService *gameScriptService;

@property (nonatomic, strong) TTWKBindingEngine *bindingEngine;
@property (nonatomic, strong) TTJavaScript *mainScriptContext;
@property (nonatomic, strong) TTJavaScript *openDataScriptContext;

//是否在分享面板展示开启“游戏盒子”的入口 默认不展示，根据后台的协议来决定
@property (nonatomic, assign) BOOL showEnableBoxFloat;

@property (nonatomic, assign, readonly) BOOL isMoreBtnClicked;

/**
 停止渲染逻辑（仅用于小游戏中广告跳转小游戏）
*/
- (void)stopRenderBeforeDismiss;


/**
 检查GLError
*/
- (NSString*)checkGLError;

/**
 触发垃圾回收
 */
- (void)triggerGC;

/**
 是否默认显示性能面板，默认值：NO
*/
- (void)enablePerformanceMonitor:(BOOL)flag;

/**
 抛系统事件接口
 目前
 qq.onAudioInterruptionEnd
 qq.onAudioInterruptionBegin
 @param event 事件名
 @param info 事件参数
 */
- (void)onSystemEvent:(NSString *)event info:(NSDictionary *)info;

/**
 关闭挽留弹窗
 */
- (void)popRecommendAlert:(NS_MINI_INTERFACE_StModuleInfo*)info;
- (void)removeRecommendAlert;
/**
 数据是否可用
 */
- (BOOL)isAlertDataAvailable:(NS_MINI_INTERFACE_StModuleInfo*)info;

#pragma mark - 录屏

- (void)startRecording;

- (void)stopRecording;

- (void)pauseGameAndForcePortrait;

- (void)resumeGameAndCancelForcePortrait;

#pragma mark - 游戏任务相关

- (void)completeGameBoxTask:(NSString *)taskId;

// 隐藏盒子浮层
- (void)popBackFloating;
// 展示游戏盒子浮点
- (void)showFloatingBox;
// 隐藏游戏盒子浮点
- (void)hideFloatingBox;

- (void)showOpenBoxTips;

// 移除游戏盒子红点
- (void)removeFloatingBoxRedDot;

- (void)showShareActionSheet;

#pragma mark - hippy相关
// 是否是hippy的
- (BOOL)isHippy;
- (NSDictionary *)hippyLaunchParamUseExtraData:(BOOL)useExtraData;
- (void)hippyBackHome;

@end

NS_ASSUME_NONNULL_END


